package com.naicheng.ivote.views;

import com.naicheng.ivote.R;
import android.annotation.SuppressLint;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.LinearLayout.LayoutParams;

@SuppressLint("ResourceAsColor")
public class CommonActivity extends TabActivity implements
		OnCheckedChangeListener {

	protected TabHost tabHost;
	
	protected RadioGroup radioGroup;
	protected RelativeLayout bottom_layout;
	protected String flag;
	protected ImageView img;

	protected RadioButton radio_1;
	protected RadioButton radio_2;
	protected RadioButton radio_3;
	protected RadioButton radio_4;
	protected RadioButton radio_5;
	protected int startLeft = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.maintab);
		initView();
		setRadioText();
		initTab();
	}

	@SuppressLint("ResourceAsColor")
	private void initView() {
		radio_1 = (RadioButton) findViewById(R.id.radio_1);
		radio_2 = (RadioButton) findViewById(R.id.radio_2);
		radio_3 = (RadioButton) findViewById(R.id.radio_3);
		radio_4 = (RadioButton) findViewById(R.id.radio_4);
		radio_5 = (RadioButton) findViewById(R.id.radio_5);

//		radio_1.setBackgroundColor(R.color.common_navi_selector);
//		radio_2.setBackgroundColor(R.color.common_navi_selector);
//		radio_3.setBackgroundColor(R.color.common_navi_selector);
//		radio_4.setBackgroundColor(R.color.common_navi_selector);
//		radio_5.setBackgroundColor(R.color.common_navi_selector);
	}

	private void setRadioText() {

		radio_1.setText("最热");
		radio_2.setText("分类");
		radio_3.setText("+");
		radio_4.setText("发现");
		radio_5.setText("我的");
	}

	private void initTab() {
		bottom_layout = (RelativeLayout) findViewById(R.id.layout_bottom);
		tabHost = getTabHost();
		tabHost.addTab(tabHost.newTabSpec("radio_1").setIndicator("radio_1")
				.setContent(new Intent(this, HotMainActivity.class)));
		tabHost.addTab(tabHost.newTabSpec("radio_2").setIndicator("radio_2")
				.setContent(new Intent(this, TypeMainActivity.class)));
		tabHost.addTab(tabHost.newTabSpec("radio_3").setIndicator("radio_3")
				.setContent(new Intent(this, PublishMainActivity.class)));
		tabHost.addTab(tabHost.newTabSpec("radio_4").setIndicator("radio_4")
				.setContent(new Intent(this, FindMainActivity.class)));
		tabHost.addTab(tabHost.newTabSpec("radio_5").setIndicator("radio_5")
				.setContent(new Intent(this, MineMainActivity.class)));
		radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
		radioGroup.setOnCheckedChangeListener(this);
	}

	@Override
	public void onCheckedChanged(RadioGroup arg0, int arg1) {
		switch (arg1) {
		case R.id.radio_1:
			tabHost.setCurrentTabByTag("radio_1");
			// MoveBg.moveFrontBg(img, startLeft, 0, 0, 0);
			// startLeft = 0;
			break;
		case R.id.radio_2:
			tabHost.setCurrentTabByTag("radio_2");
			// MoveBg.moveFrontBg(img, startLeft, img.getWidth(), 0, 0);
			// startLeft = img.getWidth();
			break;
		case R.id.radio_3:
			// ConstantValue.DEFAULT_INDEX = ConstantValue.SNS_LINKEDIN;
			tabHost.setCurrentTabByTag("radio_3");
			// MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 2, 0, 0);
			// startLeft = img.getWidth() * 2;
			break;
		case R.id.radio_4:
			tabHost.setCurrentTabByTag("radio_4");
			// MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 3, 0, 0);
			// startLeft = img.getWidth() * 3;
			break;
		case R.id.radio_5:
			tabHost.setCurrentTabByTag("radio_5");
			// MoveBg.moveFrontBg(img, startLeft, img.getWidth() * 3, 0, 0);
			// startLeft = img.getWidth() * 3;
			break;
		default:
			break;
		}
	}
}
